<template>
	<view>
		<view style="padding:50rpx;">
			<fui-upload-video max="2" immediate :url="url" ref="upload" @success="success" @error="error"
				@complete="complete"></fui-upload-video>
		</view>
		<button class="sub-btn" @click="backMyPage">保存</button>
		<!-- <button class="submitBtn" @click="backMyPage">保存</button> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//上传接口地址
				url: 'https://api.meimo.comdns.cn/common/Upload/upload?file=vipvideo&type=video',
				//上传状态，用于保存或其他操作时做判断
				status: '',
				//上传的视频地址列表
				urls: []
			};
		},
		methods: {
			//上传成功时触发
			success(e) {
				// console.log(e)
				//e.res 为服务器返回数据
				//上传成功回调，处理服务器返回数据【此处根据实际返回数据进行处理】
				let res = JSON.parse(e.res.data.replace(/\ufeff/g, "") || "{}")
				this.status = e.status
				if (res.fileName) {
					//处理结果返回给组件 
					//res.data.url为上传成功后返回的视频地址
					//e.index为视频索引值
					this.$refs.upload.result(this.$baseUrl + res.fileName, e.index)
				}
			},
			//上传失败时触发
			error(e) {
				this.status = e.status
			},
			//选择视频或上传完成时触发
			complete(e) {
				this.status = e.status
				this.urls = e.urls
				if (this.status === 'success' && e.action === 'upload') {
					// this.fui.toast('上传完成！')
					//已上传完成的视频列表 this.urls
					// console.log('this.urls', this.urls)

					this.$httpost('/UserAction/saveMyVipVideo', {
						uploadUrls: this.urls
					}).then(res => {
						if (res.code == 200) {}
					});
				}
			},
			backMyPage() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	.submitBtn {
		background-color: $globalColor;
		color: #000;
		font-size: 28rpx;
		border: 0rpx solid $globalColor;
		width: 80vw;
		height: 70rpx;
		line-height: 70rpx;
		margin: auto
	}
</style>